//
//  FinishJobAlertViewController.swift
//  ezyform
//
//  Created by MoennigQ on 20/4/20.
//  Copyright © 2020 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit

class FinishJobAlertViewForDerRegister: View {
    var okClosure:(()->Void)?
    var toDERRegistClose:(()->Void)?
    override func setUpView() {
        self.backgroundColor = UIColor.black.withAlphaComponent(0.8)
        //back view
        let backView = UIView()
        backView.backgroundColor = UIColor.white
        self.addSubview(backView)
        backView.layer.cornerRadius = Constant.BackViewCornerRadius
        backView.snp.makeConstraints { (make) in
            make.width.equalTo(300)
            make.height.greaterThanOrEqualTo(0)
            make.center.equalToSuperview()
        }
        let okImageView = UIImageView(image: UIImage(named: "installation_detail_finishjob_alert_ok"))
        backView.addSubview(okImageView)
        okImageView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(24)
            make.width.height.equalTo(50)
            make.centerX.equalToSuperview()
        }
        //finish successfully tips
        let titleLabel = ContentLabel(R.font.sfProTextRegular(size: 15))
        titleLabel.text = NSLocalizedString("pvd.detail.finishedJob", comment: "")
        titleLabel.numberOfLines = 0
        backView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(okImageView.snp.bottom).offset(16)
            make.centerX.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        
        //horizonal line view
        let lineView = UIView()
        lineView.backgroundColor = UIColor(hexStr: "#0000001A")
        backView.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(27)
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
        }
        //vertial line view
        let lineView1 = UIView()
        lineView1.backgroundColor = UIColor(hexStr: "#0000001A")
        backView.addSubview(lineView1)
        lineView1.snp.makeConstraints { (make) in
            make.top.equalTo(lineView.snp.bottom).offset(3)
            make.height.equalTo(48)
            make.width.equalTo(1)
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-4)
        }
        //
        let derRegisterBtn = UIButton(type: UIButton.ButtonType.custom)
        backView.addSubview(derRegisterBtn)
        derRegisterBtn.snp.makeConstraints { (make) in
            make.top.equalTo(lineView)
            make.left.equalToSuperview()
            make.right.equalTo(lineView1)
            make.bottom.equalToSuperview()
        }
        
        let attrStringNo = NSMutableAttributedString(string: R.string.localizable.derRegister())
        let attrNo: [NSAttributedString.Key : Any] = [.font: R.font.interSemiBold(size: 17 * Constant.currentSizeScale)!,.foregroundColor: UIColor(hexStr: "#379657")]
        attrStringNo.addAttributes(attrNo, range: NSRange(location: 0, length: attrStringNo.length))
        derRegisterBtn.setAttributedTitle(attrStringNo , for: UIControl.State.normal)
        derRegisterBtn.addTarget(self, action: #selector(derRegisterBtnClick), for: UIControl.Event.touchUpInside)
        //ok button
        let okBtn = UIButton(type: UIButton.ButtonType.custom)
        backView.addSubview(okBtn)
        okBtn.snp.makeConstraints { (make) in
            make.top.equalTo(lineView)
            make.left.equalTo(lineView1)
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        
        let attrStringOK = NSMutableAttributedString(string: R.string.localizable.oK())
        attrStringOK.addAttributes(attrNo, range: NSRange(location: 0, length: attrStringOK.length))
        okBtn.setAttributedTitle(attrStringOK , for: UIControl.State.normal)
        okBtn.addTarget(self, action: #selector(okBtnClick), for: UIControl.Event.touchUpInside)
        
    }
    @objc
    func okBtnClick(){
        self.removeFromSuperview()
        self.okClosure?()
    }
    @objc
    func derRegisterBtnClick(){
        self.removeFromSuperview()
        self.toDERRegistClose?()
        
    }
}
